Ext.BLANK_IMAGE_URL = '../ext/resources/images/default/s.gif';
Ext.ux.LoggerList = Ext.extend(Ext.Panel, {
	border:false,
	layout : 'border',
	title:'系统日志列表',
	closable : 'true',
	initComponent : function() {
		var basePath = document.getElementById("basePath").href;
		var loggerListUrl = basePath + 'logger/list.action';
		var limit = 20;
	
		var loggerStore = new Ext.data.Store({
			storeId:'loggerStore',
			proxy:new Ext.data.HttpProxy({url: loggerListUrl}),
		    reader : new Ext.data.JsonReader({
			    idProperty: 'id',       
			    root: 'loggerList',
			    totalProperty: 'loggerTotal',
			    remoteSort: true,
			    
			    fields: [
			        {name: 'id', mapping:'id', type:'int'},
			        {name: 'target', mapping:'target', type:'string'},
			        {name: 'doWhat', mapping:'doWhat', type:'string'},
			        {name: 'createDate', mapping:'createDate', type:'string'}
			    ]    
			})
		});
		
		var searchFrom = new Ext.form.FormPanel({
			title : '查找选项',
			id:'searchLoggerForm',
			region : 'west',
			layout : 'vbox',
			collapsible : true,
			width : 200,
			maxWidth : 200,
			minWidth : 200,
			frame : true,
			split : true,
			layoutConfig : {align : 'stretch'},
			items : [ {
				xtype : 'displayfield',
				value : '时间：从',
				margins : '0 0 0 5',
				width : 50
			}, {
				xtype : 'datefield',
				id:'fromDateLogger',
				editable:false,
				format:'Y-m-d'
			}, {
				xtype : 'displayfield',
				value : '到',
				margins : '0 5 0 5',
				width : 15
			}, {
				xtype : 'datefield',
				id:'toDateLogger',
				editable:false,
				format:'Y-m-d'
			}, {
				xtype : 'button',
				text : '搜索',
				listeners:{
					click:function(btn, event) {
						var params = Ext.getCmp('searchLoggerForm').getForm().getValues();
						var searchUrl = basePath + 'logger/search.action?fromDate=' + params.fromDateLogger +
							'&toDate=' + params.toDateLogger;
						loggerStore.proxy.setUrl(searchUrl);
						loggerStore.load({params:{start:0, limit:limit}});
					}
				}
			}, {
				xtype : 'button',
				text : '显示全部',
				margins : '0 5 0 5',
				listeners:{
					click:function(btn, event) {
						loggerStore.proxy.setUrl(loggerListUrl);
						loggerStore.load({params:{start:0, limit:limit}});
					}
				}
			} ]
		});
		
		this.items = [searchFrom, {
			xtype : 'grid',
			title : '系统日志列表',
			id : 'loggerDataGrid',
			region : 'center',
			split : true,
			frame : true,
			loadMask: true,
			sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
			autoScroll:true,
			ds : loggerStore,
			columns : [ {
				xtype : 'gridcolumn',
				dataIndex : 'id',
				header : '序号',
				sortable : true,
				width : 40
			}, {
				xtype : 'gridcolumn',
				dataIndex : 'target',
				header : '操作对象',
				sortable : true,
				width : 180
			}, {
				xtype : 'gridcolumn',
				dataIndex : 'doWhat',
				header : '操作',
				sortable : true,
				width : 200
			}, {
				xtype : 'gridcolumn',
				dataIndex : 'createDate',
				header : '添加日期',
				sortable : true,
				width : 140
			}],
			bbar: new Ext.PagingToolbar({
	            pageSize: limit,
	            store: loggerStore,
	            beforePageText:"当前第",   
	            afterPageText:"页，共{0}页",   
	            lastText:"尾页",   
	            nextText :"下一页",   
	            prevText :"上一页",   
	            firstText :"首页",   
	            refreshText:"刷新页面",   
	            displayInfo: true,
	            displayMsg: '显示第 {0} 条到 {1} 条记录，共 {2} 条',
	            emptyMsg: "没有记录"
	        }),
	        tbar:[{
	        	text:'查看',
	        	tooltip:'View A Record',
	        	iconCls:'open',
	        	handler:function() {
	        		var linenum = Ext.getCmp("loggerDataGrid").getSelectionModel().lastActive;
	        		if(getType(linenum) == "number") {
		        		new Ext.ux.ViewLogger({idString:'loggerDataGrid'}).show(this);
	        		} else {
	        			Ext.Msg.alert('警告', '未选中任何行');
	        		}
	        	}
	        }]
		} ];
		Ext.ux.LoggerList.superclass.initComponent.call(this);
		loggerStore.load({params:{start:0, limit:limit}});
	}
});
Ext.reg('lgnLoggerList', Ext.ux.LoggerList);